package charts;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

public class BarChart {
	private static CategoryDataset createDataset() {
		String series1 = "First";
		String series2 = "Second";
		String series3 = "Third";
		String category1 = "Category 1";
		String category2 = "Category 2";
		String category3 = "Category 3";
		String category4 = "Category 4";
		String category5 = "Category 5";
		DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
		defaultcategorydataset.addValue(1.0D, series1, category1);
		defaultcategorydataset.addValue(4D, series1, category2);
		defaultcategorydataset.addValue(3D, series1, category3);
		defaultcategorydataset.addValue(5D, series1, category4);
		defaultcategorydataset.addValue(5D, series1, category5);

		defaultcategorydataset.addValue(5D, series2, category1);
		defaultcategorydataset.addValue(7D, series2, category2);
		defaultcategorydataset.addValue(6D, series2, category3);
		defaultcategorydataset.addValue(8D, series2, category4);
		defaultcategorydataset.addValue(4D, series2, category5);

		defaultcategorydataset.addValue(4D, series3, category1);
		defaultcategorydataset.addValue(3D, series3, category2);
		defaultcategorydataset.addValue(2D, series3, category3);
		defaultcategorydataset.addValue(3D, series3, category4);
		defaultcategorydataset.addValue(6D, series3, category5);
		return defaultcategorydataset;
	}

	private static void createChart(CategoryDataset categorydataset, String path, String title) {
		JFreeChart jfreechart = ChartFactory.createBarChart("Bar Chart Demo", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, // 垂直显示
				true, true, false);
		ChartUtils.saveChart(jfreechart,path);
		System.out.println("draw chart finish");
	}

	public static void main(String args[]) {

		createChart(createDataset(), "charts/pieChart.jpg", "this is title");
	}
}
